<?php
require_once "./db_config.php";
$name="'".$_POST['姓名']."'";
$dept="'".$_POST['科室']."'";
$ryxz="'".$_POST['ryxz']."'";
$id="'".$_POST['工号']."'";
if(isset($_POST['性别'])){
    $gender=$_POST['性别'];
}else{
    $gender='';
}
if(isset($_POST['headUrl'])){
  $headUrl=$_POST['headUrl'];
}else{
  $headUrl='';
}
if(isset($_POST['国籍'])){
    $country=$_POST['国籍'];
}else{
    $country='';
}
if(isset($_POST['籍贯'])){
    $native=$_POST['籍贯'];
}else{
    $native='';
}
if(isset($_POST['民族'])){
    $nation=$_POST['民族'];
}else{
    $nation='';
}
if(isset($_POST['民族'])){
    $nation=$_POST['民族'];
}else{
    $nation='';
}
if(isset($_POST['当前职称晋升日期'])){
    $date_title=$_POST['当前职称晋升日期'];
}else{
    $date_title='';
}
if(isset($_POST['当前层级晋升日期'])){
    $date_level=$_POST['当前层级晋升日期'];
}else{
    $date_level='';
}
if(isset($_POST['当前职务晋升日期'])){
    $date_duties=$_POST['当前职务晋升日期'];
}else{
    $date_duties='';
}
if(isset($_POST['最高学历获取时间'])){
    $date_education=$_POST['最高学历获取时间'];
}else{
    $date_education='';
}
if(isset($_POST['学位'])){
    $degree=$_POST['学位'];
}else{
    $degree='';
}
if(isset($_POST['学历'])){
    $education=$_POST['学历'];
}else{
    $education='';
}
if(isset($_POST['教育形式'])){
    $type_eduction=$_POST['教育形式'];
}else{
    $type_eduction='';
}
if(isset($_POST['婚姻状况'])){
    $married=$_POST['婚姻状况'];
}else{
    $married='';
}
if(isset($_POST['出生日期'])){
    $datetime=$_POST['出生日期'];
}else{
    $datetime='';
}
if(isset($_POST['政治面貌'])){
    $politics=$_POST['政治面貌'];
}else{
    $politics='';
}
if(isset($_POST['证件类型'])){
    $type_certificate=$_POST['证件类型'];
}else{
    $type_certificate='';
}
if(isset($_POST['证件号码'])){
    $id_certificate=$_POST['证件号码'];
}else{
    $id_certificate='';
}
if(isset($_POST['档案编号'])){
    $id_document=$_POST['档案编号'];
}else{
    $id_document='';
}
if(isset($_POST['人员类别'])){
    $type_personnel=$_POST['人员类别'];
}else{
    $type_personnel='';
}
if(isset($_POST['人员层级'])){
    $level=$_POST['人员层级'];
}else{
    $level='';
}
if(isset($_POST['岗位类别'])){
    $type_post=$_POST['岗位类别'];
}else{
    $type_post='';
}
if(isset($_POST['职务'])){
    $duties=$_POST['职务'];
}else{
    $duties='';
}
if(isset($_POST['执业证书编号'])){
    $id_D_certificate=$_POST['执业证书编号'];
}else{
    $id_D_certificate='';
}
if(isset($_POST['执业证书有效期'])){
    $date_D_certificate=$_POST['执业证书有效期'];
}else{
    $date_D_certificate='';
}
// ,学术团体任职情况,从事专业,参加工作日期,
//         来院日期,返聘时间,手机号码,办公电话,毕业院校,联系人单位,工龄,院龄,岗位性质

if($name){
            $sql="SELECT COUNT(姓名) from personalfiles WHERE 工号=$id";
            $result = mysqli_query($conn, $sql);
            $row = mysqli_fetch_assoc($result);
            if($row['COUNT(姓名)']=='0'){
                $sql="INSERT INTO personalfiles
                (`姓名`,`科室`,`ryxz`,`工号`,`性别`,`国籍`,`籍贯`,`民族`,`当前职称晋升日期`,`当前职务晋升日期`,`最高学历获取时间`,`当前层级晋升日期`,`学位`,`学历`,
                `教育形式`,`婚姻状况`,`出生日期`,`政治面貌`,`证件类型`,`证件号码`,`档案编号`,`人员类别`,`岗位类别`,`管理职务`,`执业证书编号`,`执业证书有效期`,`state`,`headUrl`)
                VALUE ($name,$dept,$ryxz,$id,'$gender','$country','$native','$nation','$date_title','$date_duties','$date_education','$date_level',
                '$degree','$education','$type_eduction','$married','$datetime','$politics','$type_certificate','$id_certificate','$id_document','$type_personnel',
                '$type_post','$duties','$id_D_certificate','$date_D_certificate',3,'$headUrl')";
                $result = mysqli_query($conn, $sql);
                $sql="INSERT INTO personalfiles_temp
                (`姓名`,`科室`,`ryxz`,`工号`,`性别`,`国籍`,`籍贯`,`民族`,`当前职称晋升日期`,`当前职务晋升日期`,`最高学历获取时间`,`当前层级晋升日期`,`学位`,`学历`,
                `教育形式`,`婚姻状况`,`出生日期`,`政治面貌`,`证件类型`,`证件号码`,`档案编号`,`人员类别`,`岗位类别`,`管理职务`,`执业证书编号`,`执业证书有效期`,`state`,`headUrl`)
                VALUE ($name,$dept,$ryxz,$id,'$gender','$country','$native','$nation','$date_title','$date_duties','$date_education','$date_level',
                '$degree','$education','$type_eduction','$married','$datetime','$politics','$type_certificate','$id_certificate','$id_document','$type_personnel',
                '$type_post','$duties','$id_D_certificate','$date_D_certificate',3,'$headUrl')";
                $result = mysqli_query($conn, $sql);
                if(! $result )
                {
                    die('error: ' . mysqli_error($conn));
                }else{
                    echo "success";
                }
            }else{
                $sql="UPDATE personalfiles_temp SET
                `姓名`=$name,`科室`=$dept,`ryxz`=$ryxz,`性别`='$gender',`国籍`='$country',`籍贯`='$native',`民族`='$nation',`当前职称晋升日期`='$date_title',
                `当前职务晋升日期`='$date_duties',`最高学历获取时间`='$date_education',`当前层级晋升日期`='$date_level',`学位`='$degree',`学历`='$education',
                `教育形式`='$type_eduction',`婚姻状况`='$married',`出生日期`='$datetime',`政治面貌`='$politics',`证件类型`='$type_certificate',
                `证件号码`='$id_certificate',`档案编号`='$id_document',`人员类别`='$type_personnel',`岗位类别`='$type_post',`管理职务`='$duties',
                `执业证书编号`='$id_D_certificate',`执业证书有效期`='$date_D_certificate',`state`=1,`headUrl`='$headUrl' WHERE `工号`=$id";
                $result = mysqli_query($conn, $sql);
                if(! $result )
                {
                    die('error: ' . mysqli_error($conn));
                }else{
                    $sql="UPDATE personalfiles SET state=2 WHERE `工号`=$id";
                    $result = mysqli_query($conn, $sql);
                    if(! $result){
                        die('error: ' . mysqli_error($conn));
                    }else{
                        echo "success";
                    }
                }
            }
    }
// echo json_encode($arr,JSON_UNESCAPED_UNICODE);
mysqli_close($conn);
?>
